/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.peersim.pastry.protocol;

import com.google.code.peersim.pastry.protocol.PastryResourceAssignLsnrIfc.ResourceAssignedInfo;

/**
 * Interface that components willing to receive notifications related to
 * resource-discovery events must implement.
 *
 * @author frusso
 * @version 0.1
 * @since 0.1
 */
public interface PastryResourceDiscoveryLsnrIfc {

  /**
   * Notifies that a resource has been discovered.
   *
   * @param info The notification
   */
  public void resourceDiscovered(ResourceDiscoveredInfo info);

  /**
   * Immutable class for representing notifications for resource-discovery events.
   *
   * @author frusso
   * @version 0.1
   * @since 0.1
   */
  public static class ResourceDiscoveredInfo extends ResourceAssignedInfo {

    private final PastryId resourceId;

    /**
     * Constructor.
     *
     * @param resId The discovered resource id
     * @param hops The hops
     * @param node The node owning the resource
     */
    public ResourceDiscoveredInfo(PastryResource<?> res, PastryId resId, int hops, PastryNode node) {
      super(res,hops,node);
      resourceId = resId;
    }

    /**
     * Returns the discovered resource id.
     *
     * @return The resource id
     */
    public PastryId getResourceId() {
      return resourceId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
      return "RES_DISCOVERED resourceId: "+resourceId;
    }
  }
}